<template>
  <div class="topbar flex-ce">
    <span
      style="
        position: absolute;
        left: 0;
        top: 10px;
        font-size: 28px;
        color: #82bfff;
        font-family: cursive;
      "
    >
      <!-- <img src="@/assets/img/zenner.png" alt="" class="zennerlogo" /> -->
      {{ subCompanyName }}
    </span>
    <img src="@/assets/img/bg_top.png" alt="" class="bg" />

    <div class="logo">GIS管网领导驾驶舱</div>
    <div class="weather flex-ar">
      <el-select
        v-model="value1"
        style="width: 9vw; margin-bottom: 0.5vh"
        size="small"
        @change="f_Change"
      >
        <el-option label="智慧燃气驾驶舱" value="智慧燃气驾驶舱" />
        <el-option label="GIS管网领导驾驶舱" value="GIS管网领导驾驶舱" />
      </el-select>
      <span>{{ date }} {{ time }} {{}}</span>
      <span class="mr-[0.6vw] ml-[0.5!important]">{{ weatherData.city }}</span>
      <span class="mr-[0.6vw] ml-[0!important]">
        {{ weatherData.weather }}</span
      >
      <span class="mr-[0.2vw] ml-[0!important]">
        {{ weatherData.temperature }}℃</span
      >

      <el-dropdown trigger="click">
        <div class="flex-center">
          <span class="user"><i-ep-User class="text-[12px] mt-[-2px]" /></span>
          <b></b>
        </div>
        <template #dropdown>
          <el-dropdown-menu>
            <el-dropdown-item @click="logout">
              {{ $t("navbar.logout") }}
            </el-dropdown-item>
            <el-dropdown-item @click="toHome"> 返回首页 </el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
    </div>
  </div>
</template>

<script setup lang="ts">
import TaskSetAPI from "@/api/TaskSetAPI";
import moment from "moment";
import { useTagsViewStore, useUserStore } from "@/store";
import router from "@/router";
import { api_Weather } from "@/api/base.ts";
const userStore = useUserStore();
const tagsViewStore = useTagsViewStore();
const time = ref("");
const date = ref("");
const tab = ref(1);
const weatherData = ref({ province: "" });
const value1 = ref("GIS管网领导驾驶舱");
const subCompanyName = ref("");

// 获取天气
function f_GetWeather() {
  api_Weather().then((res) => {
    weatherData.value = res.lives[0];
  });
}

// 返回当前时间
function f_GetTime() {
  return moment().format("YYYY-MM-DD HH:mm:ss");
}

// 返回首页
function toHome() {
  router.push(`/dashboard`);
}

function f_HandelQuery() {
  TaskSetAPI.api_query_userinfo().then(({ data, succeeded }) => {
    if (succeeded) {
      subCompanyName.value = data.subCompanyName;
    }
  });
}

// 退出
function logout() {
  userStore
    .logout()
    .then(() => {
      tagsViewStore.delAllViews();
    })
    .then(() => {
      router.push(`/login`);
    });
}

function updateTime() {
  var cd = new Date();
  time.value =
    zeroPadding(cd.getHours(), 2) +
    ":" +
    zeroPadding(cd.getMinutes(), 2) +
    ":" +
    zeroPadding(cd.getSeconds(), 2);
  date.value =
    zeroPadding(cd.getFullYear(), 4) +
    "-" +
    zeroPadding(cd.getMonth() + 1, 2) +
    "-" +
    zeroPadding(cd.getDate(), 2) +
    "";
}

function zeroPadding(num: number, digit: number) {
  var zero = "";
  for (var i = 0; i < digit; i++) {
    zero += "0";
  }
  return (zero + num).slice(-digit);
}

function f_Change() {
  if (value1.value == "智慧燃气驾驶舱") {
    // window.open("http://106.14.8.236:10083/#/security");
    window.location.href = "http://106.14.8.236:10083/#/security";
  }
}

onMounted(() => {
  f_HandelQuery();
  f_GetWeather();
  setInterval(() => {
    updateTime();
  }, 1000);
});
</script>
<style lang="scss" scoped>
.topbar {
  position: relative;
  height: 8.8vh;

  .zennerlogo {
    position: absolute;
    top: 2.5vh;
    left: 2.5vh;
    z-index: 1000;
    height: 2.5vh;
    cursor: pointer;
    box-shadow: 0 0 42px #0475ff;
  }

  :deep .el-select__wrapper {
    background: #03a9f429;
    box-shadow: 0 0 0 1px #dcdfe661 inset;
  }

  :deep .el-select__placeholder {
    font-size: 12px;
    color: #aceeff9a;
  }

  .bg {
    position: absolute;
    top: 0;
    left: 50%;
    width: 100%;
    transform: translateX(-50%);
  }

  .ul1 {
    position: absolute;
    top: 3vh;
    left: 12vw;

    li {
      position: relative;
      width: 12vw;
      color: #fff;
      text-align: center;
      text-indent: 2em;
      cursor: pointer;

      > a {
        display: block;
        height: 4.6vh;
        font-family: YouSheBiaoTiHei, sans-serif;
        font-size: 1.6vh;
        line-height: 3.8vh;
        color: #fff;
        letter-spacing: 1px;
        background-image: url("@/assets/img/nav1.png");
        // font-weight: bold;
        background-repeat: no-repeat;
        background-position: center;
        background-size: 100% 100%;

        &.router-link-active {
          background-image: url("@/assets/img/nav1_on.png");
        }
      }

      .dropdown {
        position: absolute;
        top: 4vh;
        z-index: 100000;
        display: none;
        padding: 1vh;
        background: #013147;
        border-radius: 0.8vh;

        div {
          height: 4vh;
          margin-bottom: 0.8vh;
          font-size: 0.6vw;
          line-height: 4vh;
          color: #aceeff;
          letter-spacing: 2px;
          cursor: pointer;
          background-image: url("../assets/img/bg_type3.png");
          // background-color: #ffffff83;
          background-size: 100% 100%;
        }

        div:hover {
          color: #fff;
          background-color: rgb(255 255 0 / 21.2%);
          border-radius: 0.8vh;
        }
      }

      .dropdown.right {
        left: 0;
        width: 95%;
      }

      .dropdown.left {
        left: 1.2vw;
        width: 90%;
      }
    }

    li:hover {
      .dropdown {
        display: block;
      }
    }
  }

  .logo {
    position: absolute;
    top: 0.2vh;
    left: 50%;
    font-family: YouSheBiaoTiHei, sans-serif;
    font-size: 2vw;
    color: #fff;
    letter-spacing: 0.6vh;
    transform: translateX(-50%);
  }

  .ul2 {
    right: 0.8vw;
    left: auto;

    li {
      text-indent: 0;

      a {
        background-image: url("@/assets/img/nav2.png");

        &.router-link-active {
          background-image: url("@/assets/img/nav2_on.png");
        }
      }
    }
  }

  .weather {
    position: absolute;
    top: 3.5vh;
    right: 0;
    width: 20vw;
    margin-top: -0.5vh;
    font-size: 1vh;
    text-align: right;

    .user {
      cursor: pointer;
      border: 1px solid #85d9f3d1;
      border-radius: 50%;
    }

    img {
      width: 0.7vw;
      margin-right: 0.5vw;
      margin-left: 0.5vw;
      vertical-align: text-bottom;
    }

    span {
      margin-left: 1vw;
      color: #85d9f3d1;
    }
  }

  .date {
    position: absolute;
    top: 2.5vh;
    right: 3.2vw;
    width: 15vh;
    height: 3.9vh;
    color: #fff;
    background: url("@/assets/img/bg_date.png") no-repeat;
    background-size: 100% 100%;

    .time1 {
      font-family: "Microsoft YaHei", sans-serif;
      font-size: 1.2vh;
    }

    .time2 {
      margin: -3px 0;
      font-family: MiSans, sans-serif;
      font-family: "Microsoft YaHei", sans-serif;
      font-size: 1.8vh;
      font-weight: 400;
    }
  }
}
</style>
